import { Utils } from "../common/Utils"
import { Node } from "cc"
import { Building } from "../entity/Buildings"
import { UserInfo } from "../common/UserInfo"
import { UIManager } from "../common/UIManager"

export enum CheckResult{
    Pass = '通过',
    NoFoodStore = '谷仓容量不足',
    NoStore = '仓库容量不足',
    NoResource = '资源不足',
    NoWorker = '工人忙',
    Upgrading = '升级中',
    FullLevel = '已满级',
    NoDiamond = '元宝不足',
    Removing = '拆除中',
    NoRemoveWorker = '拆除工人忙',
}
export class BuildingBtnCheck {

    /**检查建造按钮是否可用 */
    static checkBuildBtn(data:Building):CheckResult{
       

        //4、判断仓库是否足
        if (!data.isEnoughFood(false)) {
            UIManager.instance.tip(CheckResult.NoFoodStore)
            return CheckResult.NoFoodStore
        }
        if (!data.isEnoughStore(false)) {
            UIManager.instance.tip(CheckResult.NoStore)
            return CheckResult.NoStore
        }
        //5、判断资源是否足
        if (!data.haveRes(false)) {
            UIManager.instance.tip(CheckResult.NoResource)
            return CheckResult.NoResource
        }

        
        
        let idleWorker = UserInfo.instance.getIdleWorker()
        if (idleWorker.length == 0) {
            UIManager.instance.tip(CheckResult.NoWorker)
            return CheckResult.NoWorker
        }

        let innerWorker = UserInfo.instance.getInnerWorker()
        if (innerWorker.length >= 2) {
            UIManager.instance.tip(CheckResult.NoWorker)
            return CheckResult.NoWorker
        }
     
        return CheckResult.Pass
    }

    /**检查升级按钮是否可用 */
    static checkUpGrdeBtn(data:Building):CheckResult {
       

        //4、判断仓库是否足
        if (!data.isEnoughFood()) {
            UIManager.instance.tip(CheckResult.NoFoodStore)
            return CheckResult.NoFoodStore
        }
        if (!data.isEnoughStore()) {
            UIManager.instance.tip(CheckResult.NoStore)
            return CheckResult.NoStore
        }
        //5、判断资源是否足
        if (!data.haveRes()) {
            UIManager.instance.tip(CheckResult.NoResource)
            return CheckResult.NoResource
        }

        // 正在升级中的
        if(data.isBuilding){
            UIManager.instance.tip(CheckResult.Upgrading)
            return CheckResult.Upgrading
        }

        if(data.isRemoving){
            UIManager.instance.tip(CheckResult.Removing)
            return CheckResult.Removing
        }

        // 是否满级
        if(data.isMaxLevel){
            UIManager.instance.tip(CheckResult.FullLevel)
            return CheckResult.FullLevel
        }

        //6、判断工人是否忙
        let idleWorker = UserInfo.instance.getIdleWorker()
        if (idleWorker.length == 0) {
            UIManager.instance.tip(CheckResult.NoWorker)
            return CheckResult.NoWorker
        }
        if (data.uid <= 18) {
            let outerWorker = UserInfo.instance.getOuterWorker()
            if (outerWorker.length >= 2) {
                UIManager.instance.tip(CheckResult.NoWorker)
                return CheckResult.NoWorker
            }

        }

        if (data.uid > 18) {
            let innerWorker = UserInfo.instance.getInnerWorker()
            if (innerWorker.length >= 2) {
                UIManager.instance.tip(CheckResult.NoWorker)
                return CheckResult.NoWorker
            }
        }
        return CheckResult.Pass
    }


    /**检查加速按钮是否可用 */
    static checkSpeedBtn(data:Building):CheckResult {
       

       
        if (!data.haveDiamond()) {
            
            UIManager.instance.tip(CheckResult.NoDiamond)
            return CheckResult.NoDiamond
        }
      
        return CheckResult.Pass
    }
    /**检查删除按钮是否可用 */
    static chekcRemoveBtn(data:Building):CheckResult {
      

        // 正在拆除中
        if(data.isRemoving){
            UIManager.instance.tip(CheckResult.Removing)
            return CheckResult.Removing
        }

        if(data.isBuilding){
            UIManager.instance.tip(CheckResult.Upgrading)
            return CheckResult.Upgrading
        }

       
        let removeWorker = UserInfo.instance.getRemoveWorker()
        if (removeWorker.length > 0) {
            UIManager.instance.tip(CheckResult.NoRemoveWorker)
            return CheckResult.NoRemoveWorker
        }
       
        return CheckResult.Pass
    }


    
}


